/**
 * 
 */
package cosc617_blackteam;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.PriorityQueue;

/**
 * @author Laura
 * Iterator of unmade orders sorteed  by party size
 */
public class UnmadeByPartySizeIterator implements Iterator<Order>,
		I_OrderIterator {
	public PriorityQueue<Order> queue;
	public UnmadeByPartySizeIterator(ArrayList<Order> orderList){
		
		int x = orderList.size();
		if (x < 1) //so that priorityqueue doesn't throw illegal argument exceptiion
			x = 1;
		queue= new PriorityQueue<Order>(x, new Comparator<Order>(){
			public int compare(Order one, Order two){
				return one.getCustomerParty().getSize()-two.getCustomerParty().getSize();
		}
		});
		for(Order order : orderList){
			if (!order.isReady())
				queue.add(order);
		}
	}
	
	@Override
	public boolean hasNext() {
		return !queue.isEmpty();
	}

	@Override
	public Order next() {
		return queue.poll();
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();
	}

}
